import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import '@/permission' // ✅ 引入权限控制
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import axios from 'axios'
const app = createApp(App)

// ① 必须先于 router、组件、其他插件
app.use(createPinia())
// ② 再装别的
app.use(router)
app.use(ElementPlus)

app.mount('#app')

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}


// 请求日志
axios.interceptors.request.use(config => {
    console.log('[AXIOS REQUEST]', config.method.toUpperCase(), config.url, config.params || config.data)
    return config
})

// 响应日志
axios.interceptors.response.use(res => {
    console.log('[AXIOS RESPONSE]', res.config.url, res.data)
    return res
})

// 路由日志
router.beforeEach((to, from, next) => {
    console.log('[ROUTE]', from.path, '->', to.path)
    next()
})